﻿using System.Web;
using IDal;

namespace DalFactory
{
    public class DalSessionUtil
    {
        public static IDalSession GetCurrentDalSession()
        {
            //Spring.Net工厂容器生产BllSession
            //IApplicationContext springContext = ContextRegistry.GetContext();
            //HttpContext:一次请求，HttpContext已经保证只有一个实例
            //也可以使用一次进程一个实例
            IDalSession dalSession = HttpContext.Current.Items["currentDalSession"] as IDalSession;
            if (dalSession == null)
            {
                dalSession = new DalSession();
                HttpContext.Current.Items.Add("currentDalSession", dalSession);
            }
            return dalSession;
        }
    }
}
